package com.example.practical_training_projects.mapper;

import com.example.practical_training_projects.entity.articles;
import com.example.practical_training_projects.vo.voarticlesandclass;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;
import java.util.List;

@Mapper
public interface articlesMapper {
    @Select("SELECT * FROM articles where a_uid=#{a_uid} order by create_time desc")
    List<articles> getThearticles(Integer a_uid);
    @Select("select articles.*,cls.as_class from articles join articles_class cls on articles.as_uid = cls.as_uid order by articles.create_time")
    List<voarticlesandclass> findAllarticlesandclass();

    /**
     * title为空查询所有，不为空模糊查询所有标题文章
     * @param a_title
     * @return
     */
    @Select("select articles.*,cls.as_class from articles join articles_class cls on articles.as_uid = cls.as_uid where articles.a_title like '%${a_title}%'\n" +
            "                                                                                                     order by articles.create_time")
    List<voarticlesandclass> findarticlesBytitle(String a_title);

    /**
     * as_uid不为空，title为空查询一个类别文章，不为空查询标题和类别
     * @return
     */
    @Select("select articles.*,cls.as_class from articles join articles_class cls on articles.as_uid = cls.as_uid where articles.a_title like '%${a_title}%'\n" +
            " and cls.as_uid=#{as_uid} order by articles.create_time")
    List<voarticlesandclass> findarticlesBytitleAndclassuid(@Param("as_uid") Integer as_uid,@Param("a_title")String a_title);
    @Select("select articles.a_uid,a_title,a_pictures from articles where articles.a_title like '%${a_title}%' order by articles.create_time")
            List<articles> selectauid(String a_title) ;





    @Select("SELECT * FROM articles where a_uid = #{a_uid}")
    articles findarticlesbyid(Integer a_uid);
    @Delete("DELETE FROM articles where a_uid = #{a_uid}")
    Integer deletearticlesbyid(Integer a_uid);
    @Insert("INSERT INTO articles (a_context,a_title,a_pictures,as_uid,create_time,update_time) VALUES('${a_context}','${a_title}','${a_pictures}',#{as_uid},sysdate(),sysdate())")
    Integer insertarticles(articles art);
    @Update("UPDATE articles set a_context='${a_context}',a_title='${a_title}',a_pictures='${a_pictures}',as_uid='${as_uid}',update_time=sysdate() where a_uid=${a_uid}")
    Integer updatearticles(articles art);
}
